package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.vo.StrategyStatisPersistenceVO;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisVOService;
import cn.wolfcode.luowowo.cache.vo.StrategyStatisVO;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 持久化redis中的 统计数据
 */
@Component
public class RedisDataPersistenceJob {

    @Reference
    private IStrategyStatisVOService strategyStatisVOService;

    @Reference
    private IStrategyDetailService strategyDetailService;

    @Scheduled(cron = "0/20 * * * * ?") // 每隔 20 秒执行一次
    public void redisDataPersistence() {
        List<StrategyStatisVO> strategyStatisVOList = strategyStatisVOService.strategyVoList();
        if (strategyStatisVOList != null && strategyStatisVOList.size() > 0) {
            for (StrategyStatisVO vo : strategyStatisVOList) {
                StrategyStatisPersistenceVO persistenceVO = new StrategyStatisPersistenceVO();
                BeanUtils.copyProperties(vo, persistenceVO);
                strategyDetailService.dataPersistence(persistenceVO);
            }
        }
    }
}
